package com.youhp.spire.xls.demo.Workbook;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import com.spire.xls.*;
import com.spire.xls.charts.ChartSerie;

public class EmbedNoninstalledFonts {

	public static void main(String[] args) {
		 //Create a Workbook
        Workbook workbook = new Workbook();

        //Load the document from disk
        workbook.loadFromFile("data/EmbedNoninstalledFonts.xlsx");

        //Get the first sheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Get the first chart
        Chart chart = sheet.getCharts().get(0);
        String[] paths = new String[]{ "Data/PT_Serif-Caption-Web-Regular.ttf" };
        //Load the font file from disk
        workbook.setCustomFontFilePaths(paths);
        Hashtable result = workbook.getCustomFontParsedResult(); 
       
        List valueList = new ArrayList();
        valueList.addAll(result.values());
        //Apply the font for PrimaryValueAxis of chart
        chart.getPrimaryValueAxis().getFont().setFontName((String)valueList.get(0)) ;

        //Apply the font for PrimaryCategoryAxis of chart
        chart.getPrimaryCategoryAxis().getFont().setFontName((String)valueList.get(0)) ;

        //Apply the font for the first chartSerie of chart
        ChartSerie chartSerie1 = chart.getSeries().get(0);
        chartSerie1.getDataPoints().getDefaultDataPoint().getDataLabels().setFontName((String)valueList.get(0));

        String output ="output/Output.pdf";
        //Save and Launch
        workbook.saveToFile(output,FileFormat.PDF);
	}

}
